<template>
  <!--会签管理-单据申请-付款计划弹窗-表单-->
  <a-spin :spinning="confirmLoading">
    <j-form-container class="scroll-view" style="height: 600px;" :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row style="margin-bottom: 20px;">
          <a-col :span="24">
            <span style="font-size: 20px; font-weight: bold">付款计划</span>
          </a-col>
        </a-row>

        <a-row>
          <a-col :span="12">
            <a-form-model-item label="标题" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="name">
              <a-input v-model="model.title" placeholder="请输入标题"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="项目" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="projectId">
              <a-select :options="levelOneOptions" placeholder="请选择项目" v-model="model.projectId">
              </a-select>
            </a-form-model-item>
          </a-col>
        </a-row>

        <a-row>
          <a-col :span="24">
            <div style="margin-left: 30px;line-height: 40px;font-size: 16px;font-weight: 600;">预计收款：</div>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="总金额" :labelCol="labelCol3" :wrapperCol="wrapperCol3" prop="gatheringTotal"
              style="margin-bottom: 10px;margin-left: 20px;">
              <a-input v-model="model.gatheringTotal" style="width: 314px;"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="劳务等款项" :labelCol="labelCol" :wrapperCol="wrapperCol"
              prop="gatheringPaymentServices" style="margin-bottom: 10px;">
              <a-input v-model="model.gatheringPaymentServices"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="劳务工资" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="gatheringLaborWages"
              style="margin-bottom: 30px;">
              <a-input v-model="model.gatheringLaborWages"></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>

        <a-row>
          <a-col :span="24">
            <div style="margin-left: 30px;line-height: 40px;font-size: 16px;font-weight: 600;">对下班组计划支付劳务费：</div>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="总金额" :labelCol="labelCol3" :wrapperCol="wrapperCol3" prop="serviceFeeTotal"
              style="margin-bottom: 10px;margin-left: 20px;">
              <a-input v-model="model.serviceFeeTotal" style="width: 314px;"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="劳务等款项" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="serviceFeePayment"
              style="margin-bottom: 10px;">
              <a-input v-model="model.serviceFeePayment"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="劳务工资" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="serviceFeeLaborWages"
              style="margin-bottom: 30px;">
              <a-input v-model="model.serviceFeeLaborWages"></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>

        <a-row>
          <a-col :span="24">
            <div style="margin-left: 30px;line-height: 40px;font-size: 16px;font-weight: 600;">计划支付材料等款项：</div>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="总金额" :labelCol="labelCol3" :wrapperCol="wrapperCol3"
              prop="gatheringMaterialsTotal" style="margin-bottom: 10px;margin-left: 20px;">
              <a-input v-model="model.gatheringMaterialsTotal" style="width: 314px;"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="材料费" :labelCol="labelCol" :wrapperCol="wrapperCol"
              prop="gatheringMaterialsExpense" style="margin-bottom: 10px;">
              <a-input v-model="model.gatheringMaterialsExpense"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="机械费" :labelCol="labelCol" :wrapperCol="wrapperCol"
              prop="gatheringMaterialsMachine" style="margin-bottom: 10px;">
              <a-input v-model="model.gatheringMaterialsMachine"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="其他" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="gatheringMaterialsOther"
              style="margin-bottom: 30px;">
              <a-input v-model="model.gatheringMaterialsOther"></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>

        <a-row>
          <a-col :span="24">
            <div style="margin-left: 30px;line-height: 40px;font-size: 16px;font-weight: 600;">项目部直签支出：</div>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="总金额" :labelCol="labelCol3" :wrapperCol="wrapperCol3" prop="projectTotal"
              style="margin-bottom: 10px;margin-left: 20px;">
              <a-input v-model="model.projectTotal"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="劳务费:" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="projectFeePayment"
              style="margin-bottom: 10px;">
              <a-input v-model="model.projectFeePayment"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="机械费" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="projectMachineryCost"
              style="margin-bottom: 10px;">
              <a-input v-model="model.projectMachineryCost"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="材料费" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="projectMaterialsExpense"
              style="margin-bottom: 10px;">
              <a-input v-model="model.projectMaterialsExpense"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="其他" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="projectOther"
              style="margin-bottom: 30px;">
              <a-input v-model="model.projectOther"></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>

        <a-row>
          <a-col :span="5">
            <div style="margin-left: 30px;line-height: 40px;font-size: 16px;font-weight: 600;">项目部预留备用资金：</div>
          </a-col>
          <a-col :span="19">
            <a-form-model-item label="" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="projectReservedMoney"
              style="margin-bottom: 30px;">
              <a-input v-model="model.projectReservedMoney" style="width: 100%;"></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>

        <a-row>
          <a-col :span="24">
            <a-form-model-item label="备注" :labelCol="labelCol2" :wrapperCol="wrapperCol2" prop="remark"
              style="margin-bottom: 10px;margin-left: 20px;">
              <textarea v-model="model.remark" cols="100" rows="3" style="width: 93%;"></textarea>
            </a-form-model-item>
          </a-col>
        </a-row>

        <a-row>
          <a-col :span="24">
            <a-form-model-item label="附件资料" :labelCol="labelCol2" :wrapperCol="wrapperCol2" prop="attachment"
              style="margin:0 60px 10px 20px;">
              <j-upload v-model="model.attachment"></j-upload>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
    <!-- <a-button @click="save" type="primary">保存</a-button> -->
  </a-spin>
</template>
<script>
  import {
    httpAction,
    getAction
  } from '@/api/manage'
  import {
    validateDuplicateValue
  } from '@/utils/util'

  export default {
    name: 'WtBrandForm',
    components: {},
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false,
      },
    },
    data() {
      return {
        model: {
          countersignTemplateId: '',
          attachment: ''
        },
        labelCol: {
          xs: {
            span: 24
          },
          sm: {
            span: 5
          },
        },
        wrapperCol: {
          xs: {
            span: 24
          },
          sm: {
            span: 16
          },
        },
        labelCol2: {
          xs: {
            span: 24
          },
          sm: {
            span: 2
          },
        },
        wrapperCol2: {
          xs: {
            span: 24
          },
          sm: {
            span: 22
          },
        },
        labelCol3: {
          xs: {
            span: 24
          },
          sm: {
            span: 2
          },
        },
        wrapperCol3: {
          xs: {
            span: 24
          },
          sm: {
            span: 8
          },
        },
        confirmLoading: false,
        validatorRules: {},
        levelOneOptions: [],

        treeData: [],
        fileList: [],
        url: {
          add: '/countersign/wtCountersignPaymentPlan/add',
          edit: '/wtBrand/edit',
          queryById: '/wtBrand/queryById',
        },
      }
    },
    computed: {
      formDisabled() {
        return this.disabled
      },
    },
    created() {
      //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model))
    },
    methods: {
      loadTree() {
        var that = this
        getAction(`/sys/sysDepart/getDepartByOrgType?orgType=1`).then((res) => {
          if (res.success) {
            this.treeData = []
            let treeList = res.result
            for (let a = 0; a < treeList.length; a++) {
              let temp = treeList[a]
              temp.isLeaf = temp.leaf
              this.treeData.push(temp)
            }
            this.levelOneOptions = [...this.treeData].map((v) => {
              return {
                ...v,
                value: v.id,
                label: v.departName,
              }
            })
          }
        })
      },
      add(record) {
        this.model.countersignTemplateId = record.id;
        this.edit();
      },
      edit(record) {
        //this.model = Object.assign({}, record)
        this.visible = true
        this.loadTree()
      },
      handleOk() {
        const that = this
        // 触发表单验证
        // this.$refs.form.validate((valid) => {
        //   if (valid) {
        //     that.confirmLoading = true
        //     let httpurl = ''
        //     let method = ''
        //     if (!this.model.id) {
        //       httpurl += this.url.add
        //       method = 'post'
        //     } else {
        //       httpurl += this.url.edit
        //       method = 'put'
        //     }
        //     httpAction(httpurl, this.model, method)
        //       .then((res) => {
        //         if (res.success) {
        //           that.$message.success(res.message)
        //           that.$emit('ok')
        //         } else {
        //           that.$message.warning(res.message)
        //         }
        //       })
        //       .finally(() => {
        //         that.confirmLoading = false
        //       })
        //   }
        // })
      },
      submitForm(record) {
        const that = this
        if (!this.model.attachment) {
          that.$message.warning('附件资料不能为空,请上传')
        } else {
          // 触发表单验证
          this.$refs.form.validate((valid) => {
            if (valid) {
              that.confirmLoading = true
              let httpurl = ''
              let method = ''
              that.model.status = record;
              // debugger
              httpAction('/countersign/wtCountersignPaymentPlan/add', this.model, 'POST')
                .then((res) => {
                  if (res.success) {
                    that.$message.success(res.message)
                    that.$emit('ok')
                  } else {
                    that.$message.warning(res.message)
                    that.$emit('error')
                  }
                })
                .finally(() => {
                  that.confirmLoading = false
                })
            }
          })
        }
        
      },
    },
  }
</script>
<style scoped>
  .scroll-view {
    overflow: auto;
    overflow-y: scroll;
  }
</style>